package com.ejd.web.vo.genl;

import java.util.List;





import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;


import com.ejd.service.ISubCategoryService;
import com.ejd.utils.MessageFactory;
import com.ejd.utils.SpringFacesUtil;
import com.ejd.web.bo.impl.SubCategory;
import com.ejd.web.constant.EjdConstants;
import com.ejd.web.constant.SpringBeanConstants;

@ManagedBean(name="existSubCategory")
@SessionScoped
public class ExistSubCategoryBean implements java.io.Serializable {

	private SelectItem[] subCategoryItems;

	
	

	public SelectItem[] getSubCategoryItems() {
		return subCategoryItems;
	}




	public void setSubCategoryItems(SelectItem[] subCategoryItems) {
		this.subCategoryItems = subCategoryItems;
	}




	public ExistSubCategoryBean() {
		
		ISubCategoryService<SubCategory,Long> subCategoryService = (ISubCategoryService<SubCategory,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.SUB_CATEGORY_SERVICE_BEAN_NAME);
		subCategoryService.setEntityClass(SubCategory.class);
		subCategoryService.setPKClass(Long.class);
		List<SubCategory> subCategorys = subCategoryService.getAll("serialNumber",true);
		SelectItem[] tempSubCategoryItems = new SelectItem[subCategorys.size()];
		//set select default 
		if (null != subCategorys && !(subCategorys.isEmpty())) {
			for (int i=0; i< tempSubCategoryItems.length; i++) {
				SubCategory subCategory = (SubCategory) subCategorys.get(i);
				String subCategoryNameN18 = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,subCategory.getSubCategoryName(), FacesMessage.SEVERITY_ERROR).getDetail();
				tempSubCategoryItems[i] = new SelectItem(subCategory.getSubCategoryCode(),subCategoryNameN18,subCategory.getCategoryCode());
			}
		}
		this.setSubCategoryItems(tempSubCategoryItems);
	}
}
